package com.collabscm.pf.vo;

import java.util.List;

import com.collabscm.pf.BaseObject;
import com.collabscm.pf.exception.ConfigurationException;

/**
 * 分页对象
 * @author Zeng Raoxing
 */
public class PageObject<T> extends BaseObject {
	private static final long serialVersionUID = 1L;
	/**默认每页大小*/
	public static final int Default_Page_Size = 20;
	/***/
	private Integer startIndex;
	/**每页限制大小*/
	private Integer pageSize;
	/**总记录数*/
	private Integer totalSize;
	/**当前页*/
	private Integer currentPage;
	/**总页数*/
	private Integer totalPage;

	/**具体数据列表*/
	private List<T> items;

	public PageObject() {
	}

	public PageObject(QueryParameters parameters) {
		this.startIndex = parameters.getStart();
		this.pageSize = parameters.size;
		this.currentPage = startIndex/pageSize + 1;
	}

	public Integer getStartIndex() {
		return startIndex;
	}

	public void setStartIndex(Integer startIndex) {
		this.startIndex = startIndex;
		
	}

	public Integer getPageSize() {
		return pageSize;
	}

	public void setPageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}

	public Integer getTotalSize() {
		return totalSize;
	}

	public void setTotalSize(Integer totalSize) {
		this.totalSize = totalSize;
		if(pageSize == null) {
			throw new ConfigurationException("PageObject对象必须先设置pageSize才能设置totalSize");
		}
		this.totalPage = totalSize/pageSize + 1;
	}

	public List<T> getItems() {
		return items;
	}

	public void setItems(List<T> items) {
		this.items = items;
	}
	
	public void setCurrentPage(Integer currentPage) {
		this.currentPage = currentPage;
	}

	public Integer getCurrentPage() {
		return currentPage;
	}

	public Integer getTotalPage() {
		return totalPage;
	}
	
}
